#include <iostream>
#include <queue>

using namespace std;

typedef long long LL;
const int N = 1e4 + 10;

int n, m;
LL a[N], b[N], c[N];

struct node
{
    LL f; // 函数值
    LL num; // 函数编号
    LL x; // 代入值

    bool operator <(const node& x) const
    {
        // 小根堆，大元素下坠
        return f > x.f;
    }
};

priority_queue<node> heap;

LL calc(LL i, LL x)
{
    return a[i] * x * x + b[i] * x + c[i];
}

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
    }

    // 1. 把 x = 1 的值放入堆中
    for(int i = 1; i <= n; i++)
    {
        heap.push({calc(i, 1), i, 1});
    }

    // 2. 依次拿出 m 个值
    while(m--)
    {
        auto t = heap.top(); heap.pop();
        LL f = t.f, num = t.num, x = t.x;

        cout << f << " ";
        // 把下一个函数值放入堆中
        heap.push({calc(num, x + 1), num, x + 1});
    }


    return 0;
}